use strict;
use warnings;

if(   scalar( @ARGV ) > 0
   && check_numbers( @ARGV ) )
{
	balls_main( \@ARGV );
}else{
	print "please input numbers.\n";
}

sub check_numbers{
	my @hikisu = @_;
	my $flag  = 1;
	foreach my $number ( @hikisu ){
		if( $number !~/^\d+$/ ){
			$flag = 0;
		}
	}
	return $flag;
}

sub balls_main{
	my ( $p_balls ) = @_;
	my $p_map = mapping();
	check_ball_number( $p_balls, $p_map, 0, scalar( @$p_balls ) );
	print "NO\n";
}

sub mapping{
	my $p_map;
	foreach my $LR ( 0..1 ){
		$p_map->[ $LR ]->[ 0 ] = -1;
	}
	return $p_map;
}

sub check_ball_number{
	my ( $p_balls, $p_map, $nest, $max ) = @_;
	if( $nest == $max ){
		print "YES\n";
		exit;
	}
	foreach my $LR ( 0..1 ){
		if( $p_balls->[ $nest ] > $p_map->[ $LR ]->[ -1 ]){
			push( @{$p_map->[ $LR ]}, $p_balls->[ $nest ] );
			check_ball_number( $p_balls, $p_map, $nest+1, $max );
			pop ( @{$p_map->[ $LR ]} );
		}
	}
}










1;
